class ChinaGetter:#获取中文信息
    """A simple localizer a la gettext"""
    def __init__(self):
        self.trans=dict(dog=u"小狗",cat=u"小猫")

    def get(self,msgid):
        """we' ll punt if we don't hava a translation"""
        try:
            return self.trans[msgid]
        except KeyError:
            return str(msgid)

class EnglishGetter:#获取英文信息
    """simple echoes the msg ids"""
    def get(self,msgid):
        return str(msgid) #传进来什么返回什么

def get_localizer(language="English"):#工厂函数
    """The factory method"""
    languages = dict(English=EnglishGetter,China=ChinaGetter)
    return languages[language]() #通过参数生成一个实例

#Create our localizers
e,g=get_localizer("English"),get_localizer("China")
for msgid in "dog parrot cat bear".split():
    print(e.get(msgid),g.get(msgid))